package com.dayou.service;

import com.alibaba.fastjson.JSONObject;
import com.dayou.bean.MqMessageBean;
import com.dayou.common.utils.LogUtil;
import com.dayou.handler.Producer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.Queue;


@Component
public class MqService {
    @Autowired
    private Producer mqProducer;
    @Autowired
    private LogUtil logUtil;
    @Autowired
    private Queue interviewQueue;
    public void sendMessage(MqMessageBean message){
        JSONObject messageJo = (JSONObject)JSONObject.toJSON(message);
        String msg = messageJo.toJSONString();
        mqProducer.sendTextMessage(interviewQueue,msg);
        try {
            logUtil.info(String.format("发送MQ至%s\r\n%s",interviewQueue.getQueueName(),msg));
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}
